package com.sjq.common.web;

import com.sjq.common.web.SessionUserHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "/main")
public class MainController {
    
    @Autowired
    private HttpSession session;
    
    @RequestMapping("/frame")
    public ModelAndView login(HttpServletRequest request) {
    	ModelAndView mav = new ModelAndView();
    	Object obj = request.getSession().getAttribute("account");
    	if(obj!=null){
    		mav.setViewName("/view/main/index");
    	}else{
    		mav.setViewName("/view/login/login");
    	}
        return mav;
    }
    
    @RequestMapping("/mh")
    public ModelAndView mh(HttpServletRequest request) {
    	ModelAndView mav = new ModelAndView();
    	Object obj = request.getSession().getAttribute("account");
        mav.setViewName("/view/main/index");
        return mav;
    }
    
    /**
     * 注销
     * @return
     */
    @RequestMapping("/logout")
    public ModelAndView logout() {
        SessionUserHelper helper = SessionUserHelper.createBySession(session);
        helper.clearSession();
        ModelAndView mav = new ModelAndView();
		mav.setViewName("/view/login/login");
		return mav;
    }
}